import 'package:get/get.dart';
import 'package:loader_overlay/loader_overlay.dart';
import 'package:realm/realm.dart';
import 'package:sgy_flutter/api_service.dart';
import 'package:sgy_flutter/ble/ble_manager.dart';
import 'package:sgy_flutter/ble/right_ble_manager.dart';
import 'package:sgy_flutter/widget/toast.dart';

extension GetxControllerExtension on GetxController {
  BleManager get bleManager => Get.find();

  RightBleManager get rightBleManager => Get.find();

  ApiService get apiService => Get.find();

  Realm get realm => Get.find();

  OverlayExtensionHelper? get loaderOverlay => Get.context?.loaderOverlay;

  Future showToast(String msg,
      {Duration duration = const Duration(milliseconds: 1500)}) async {

    loaderOverlay?.show(
        widgetBuilder: (_) => Toast(msg: msg), showOverlay: false);
    await Future.delayed(duration);
    loaderOverlay?.hide();
  }
}
